.class public Lnet/oauth/client/URLConnectionClient;
.super Ljava/lang/Object;
.source "URLConnectionClient.java"

# interfaces
.implements Lnet/oauth/http/HttpClient;


# static fields
.field private static final EOL:Ljava/lang/String; = "\r\n"


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 42
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method


# virtual methods
.method public execute(Lnet/oauth/http/HttpMessage;Ljava/util/Map;)Lnet/oauth/http/HttpResponseMessage;
    .locals 27
    .parameter "request"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Lnet/oauth/http/HttpMessage;",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/Object;",
            ">;)",
            "Lnet/oauth/http/HttpResponseMessage;"
        }
    .end annotation

    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 46
    .local p2, parameters:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;"
    move-object/from16 v0, p1

    iget-object v14, v0, Lnet/oauth/http/HttpMessage;->method:Ljava/lang/String;

    .line 47
    .local v14, httpMethod:Ljava/lang/String;
    move-object/from16 v0, p1

    iget-object v3, v0, Lnet/oauth/http/HttpMessage;->headers:Ljava/util/List;

    .line 48
    .local v3, addHeaders:Ljava/util/Collection;,"Ljava/util/Collection<Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;>;"
    move-object/from16 v0, p1

    iget-object v0, v0, Lnet/oauth/http/HttpMessage;->url:Ljava/net/URL;

    move-object/from16 v23, v0

    .line 49
    .local v23, url:Ljava/net/URL;
    invoke-virtual/range {v23 .. v23}, Ljava/net/URL;->openConnection()Ljava/net/URLConnection;

    move-result-object v6

    .line 50
    .local v6, connection:Ljava/net/URLConnection;
    const/16 v25, 0x1

    move/from16 v0, v25

    invoke-virtual {v6, v0}, Ljava/net/URLConnection;->setDoInput(Z)V

    .line 51
    instance-of v0, v6, Ljava/net/HttpURLConnection;

    move/from16 v25, v0

    if-eqz v25, :cond_3

    move-object v13, v6

    .line 52
    check-cast v13, Ljava/net/HttpURLConnection;

    .line 53
    .local v13, http:Ljava/net/HttpURLConnection;
    invoke-virtual {v13, v14}, Ljava/net/HttpURLConnection;->setRequestMethod(Ljava/lang/String;)V

    .line 54
    invoke-interface/range {p2 .. p2}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v25

    invoke-interface/range {v25 .. v25}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v15

    .local v15, i$:Ljava/util/Iterator;
    :cond_0
    :goto_0
    invoke-interface {v15}, Ljava/util/Iterator;->hasNext()Z

    move-result v25

    if-eqz v25, :cond_3

    invoke-interface {v15}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v21

    check-cast v21, Ljava/util/Map$Entry;

    .line 55
    .local v21, p:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/Object;>;"
    invoke-interface/range {v21 .. v21}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v19

    check-cast v19, Ljava/lang/String;

    .line 56
    .local v19, name:Ljava/lang/String;
    invoke-interface/range {v21 .. v21}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v25

    invoke-virtual/range {v25 .. v25}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v24

    .line 57
    .local v24, value:Ljava/lang/String;
    const-string v25, "followRedirects"

    move-object/from16 v0, v25

    move-object/from16 v1, v19

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v25

    if-eqz v25, :cond_1

    .line 58
    invoke-static/range {v24 .. v24}, Ljava/lang/Boolean;->parseBoolean(Ljava/lang/String;)Z

    move-result v25

    move/from16 v0, v25

    invoke-virtual {v13, v0}, Ljava/net/HttpURLConnection;->setInstanceFollowRedirects(Z)V

    goto :goto_0

    .line 59
    :cond_1
    const-string v25, "connectTimeout"

    move-object/from16 v0, v25

    move-object/from16 v1, v19

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v25

    if-eqz v25, :cond_2

    .line 60
    invoke-static/range {v24 .. v24}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v25

    move/from16 v0, v25

    invoke-virtual {v13, v0}, Ljava/net/HttpURLConnection;->setConnectTimeout(I)V

    goto :goto_0

    .line 61
    :cond_2
    const-string v25, "readTimeout"

    move-object/from16 v0, v25

    move-object/from16 v1, v19

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v25

    if-eqz v25, :cond_0

    .line 62
    invoke-static/range {v24 .. v24}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v25

    move/from16 v0, v25

    invoke-virtual {v13, v0}, Ljava/net/HttpURLConnection;->setReadTimeout(I)V

    goto :goto_0

    .line 66
    .end local v13           #http:Ljava/net/HttpURLConnection;
    .end local v15           #i$:Ljava/util/Iterator;
    .end local v19           #name:Ljava/lang/String;
    .end local v21           #p:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/Object;>;"
    .end local v24           #value:Ljava/lang/String;
    :cond_3
    new-instance v12, Ljava/lang/StringBuilder;

    invoke-direct {v12, v14}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 68
    .local v12, headers:Ljava/lang/StringBuilder;
    const-string v25, " "

    move-object/from16 v0, v25

    invoke-virtual {v12, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v25

    invoke-virtual/range {v23 .. v23}, Ljava/net/URL;->getPath()Ljava/lang/String;

    move-result-object v26

    invoke-virtual/range {v25 .. v26}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    .line 69
    invoke-virtual/range {v23 .. v23}, Ljava/net/URL;->getQuery()Ljava/lang/String;

    move-result-object v22

    .line 70
    .local v22, query:Ljava/lang/String;
    if-eqz v22, :cond_4

    invoke-virtual/range {v22 .. v22}, Ljava/lang/String;->length()I

    move-result v25

    if-lez v25, :cond_4

    .line 71
    const-string v25, "?"

    move-object/from16 v0, v25

    invoke-virtual {v12, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v25

    move-object/from16 v0, v25

    move-object/from16 v1, v22

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    .line 73
    :cond_4
    const-string v25, "\r\n"

    move-object/from16 v0, v25

    invoke-virtual {v12, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    .line 74
    invoke-virtual {v6}, Ljava/net/URLConnection;->getRequestProperties()Ljava/util/Map;

    move-result-object v25

    invoke-interface/range {v25 .. v25}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v25

    invoke-interface/range {v25 .. v25}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v15

    :cond_5
    invoke-interface {v15}, Ljava/util/Iterator;->hasNext()Z

    move-result v25

    if-eqz v25, :cond_6

    invoke-interface {v15}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v11

    check-cast v11, Ljava/util/Map$Entry;

    .line 76
    .local v11, header:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/util/List<Ljava/lang/String;>;>;"
    invoke-interface {v11}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v17

    check-cast v17, Ljava/lang/String;

    .line 77
    .local v17, key:Ljava/lang/String;
    invoke-interface {v11}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v25

    check-cast v25, Ljava/util/List;

    invoke-interface/range {v25 .. v25}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v16

    .local v16, i$:Ljava/util/Iterator;
    :goto_1
    invoke-interface/range {v16 .. v16}, Ljava/util/Iterator;->hasNext()Z

    move-result v25

    if-eqz v25, :cond_5

    invoke-interface/range {v16 .. v16}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v24

    check-cast v24, Ljava/lang/String;

    .line 78
    .restart local v24       #value:Ljava/lang/String;
    move-object/from16 v0, v17

    invoke-virtual {v12, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v25

    const-string v26, ": "

    invoke-virtual/range {v25 .. v26}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v25

    move-object/from16 v0, v25

    move-object/from16 v1, v24

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v25

    const-string v26, "\r\n"

    invoke-virtual/range {v25 .. v26}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    goto :goto_1

    .line 82
    .end local v11           #header:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/util/List<Ljava/lang/String;>;>;"
    .end local v16           #i$:Ljava/util/Iterator;
    .end local v17           #key:Ljava/lang/String;
    .end local v24           #value:Ljava/lang/String;
    :cond_6
    const/4 v7, 0x0

    .line 83
    .local v7, contentLength:Ljava/lang/String;
    invoke-interface {v3}, Ljava/util/Collection;->iterator()Ljava/util/Iterator;

    move-result-object v15

    .restart local v15       #i$:Ljava/util/Iterator;
    :goto_2
    invoke-interface {v15}, Ljava/util/Iterator;->hasNext()Z

    move-result v25

    if-eqz v25, :cond_8

    invoke-interface {v15}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v10

    check-cast v10, Ljava/util/Map$Entry;

    .line 84
    .local v10, header:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    invoke-interface {v10}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v17

    check-cast v17, Ljava/lang/String;

    .line 85
    .restart local v17       #key:Ljava/lang/String;
    const-string v25, "Content-Length"

    move-object/from16 v0, v25

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v25

    if-eqz v25, :cond_7

    instance-of v0, v6, Ljava/net/HttpURLConnection;

    move/from16 v25, v0

    if-eqz v25, :cond_7

    .line 87
    invoke-interface {v10}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v7

    .end local v7           #contentLength:Ljava/lang/String;
    check-cast v7, Ljava/lang/String;

    .line 91
    .restart local v7       #contentLength:Ljava/lang/String;
    :goto_3
    move-object/from16 v0, v17

    invoke-virtual {v12, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v25

    const-string v26, ": "

    invoke-virtual/range {v25 .. v26}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v26

    invoke-interface {v10}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v25

    check-cast v25, Ljava/lang/String;

    move-object/from16 v0, v26

    move-object/from16 v1, v25

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v25

    const-string v26, "\r\n"

    invoke-virtual/range {v25 .. v26}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    goto :goto_2

    .line 89
    :cond_7
    invoke-interface {v10}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v25

    check-cast v25, Ljava/lang/String;

    move-object/from16 v0, v17

    move-object/from16 v1, v25

    invoke-virtual {v6, v0, v1}, Ljava/net/URLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3

    .line 93
    .end local v10           #header:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    .end local v17           #key:Ljava/lang/String;
    :cond_8
    const/4 v9, 0x0

    .line 94
    .local v9, excerpt:[B
    invoke-virtual/range {p1 .. p1}, Lnet/oauth/http/HttpMessage;->getBody()Ljava/io/InputStream;

    move-result-object v5

    .line 95
    .local v5, body:Ljava/io/InputStream;
    if-eqz v5, :cond_b

    .line 97
    if-eqz v7, :cond_9

    .line 98
    :try_start_0
    move-object v0, v6

    check-cast v0, Ljava/net/HttpURLConnection;

    move-object/from16 v25, v0

    invoke-static {v7}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v26

    invoke-virtual/range {v25 .. v26}, Ljava/net/HttpURLConnection;->setFixedLengthStreamingMode(I)V

    .line 101
    :cond_9
    const/16 v25, 0x1

    move/from16 v0, v25

    invoke-virtual {v6, v0}, Ljava/net/URLConnection;->setDoOutput(Z)V

    .line 102
    invoke-virtual {v6}, Ljava/net/URLConnection;->getOutputStream()Ljava/io/OutputStream;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_1

    move-result-object v20

    .line 104
    .local v20, output:Ljava/io/OutputStream;
    :try_start_1
    new-instance v8, Lnet/oauth/client/ExcerptInputStream;

    invoke-direct {v8, v5}, Lnet/oauth/client/ExcerptInputStream;-><init>(Ljava/io/InputStream;)V

    .line 105
    .local v8, ex:Lnet/oauth/client/ExcerptInputStream;
    const/16 v25, 0x400

    move/from16 v0, v25

    new-array v4, v0, [B

    .line 106
    .local v4, b:[B
    :goto_4
    invoke-virtual {v8, v4}, Lnet/oauth/client/ExcerptInputStream;->read([B)I

    move-result v18

    .local v18, n:I
    if-lez v18, :cond_a

    .line 107
    const/16 v25, 0x0

    move-object/from16 v0, v20

    move/from16 v1, v25

    move/from16 v2, v18

    invoke-virtual {v0, v4, v1, v2}, Ljava/io/OutputStream;->write([BII)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_4

    .line 111
    .end local v4           #b:[B
    .end local v8           #ex:Lnet/oauth/client/ExcerptInputStream;
    .end local v18           #n:I
    :catchall_0
    move-exception v25

    :try_start_2
    invoke-virtual/range {v20 .. v20}, Ljava/io/OutputStream;->close()V

    throw v25
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_1

    .line 114
    .end local v20           #output:Ljava/io/OutputStream;
    :catchall_1
    move-exception v25

    invoke-virtual {v5}, Ljava/io/InputStream;->close()V

    throw v25

    .line 109
    .restart local v4       #b:[B
    .restart local v8       #ex:Lnet/oauth/client/ExcerptInputStream;
    .restart local v18       #n:I
    .restart local v20       #output:Ljava/io/OutputStream;
    :cond_a
    :try_start_3
    invoke-virtual {v8}, Lnet/oauth/client/ExcerptInputStream;->getExcerpt()[B
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    move-result-object v9

    .line 111
    :try_start_4
    invoke-virtual/range {v20 .. v20}, Ljava/io/OutputStream;->close()V
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_1

    .line 114
    invoke-virtual {v5}, Ljava/io/InputStream;->close()V

    .line 117
    .end local v4           #b:[B
    .end local v8           #ex:Lnet/oauth/client/ExcerptInputStream;
    .end local v18           #n:I
    .end local v20           #output:Ljava/io/OutputStream;
    :cond_b
    new-instance v25, Lnet/oauth/client/URLConnectionResponse;

    invoke-virtual {v12}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v26

    move-object/from16 v0, v25

    move-object/from16 v1, p1

    move-object/from16 v2, v26

    invoke-direct {v0, v1, v2, v9, v6}, Lnet/oauth/client/URLConnectionResponse;-><init>(Lnet/oauth/http/HttpMessage;Ljava/lang/String;[BLjava/net/URLConnection;)V

    return-object v25
.end method
